<?php
namespace app\mxty\model;
use think\Model;
use think\model\Pivot;

class CourseLessonClockIn extends Pivot
{
    protected $table = 'athlon_course_lesson_clock_in';
    protected $pk = 'clock_in_id';

    public function clockIn($data)
    {
      $model = $this->where(['lesson_id' => $data['lesson_id'], 'order_id' => $data['order_id'],'user_id' => $data['user_id']])->findOrEmpty();
      if($model->isEmpty()) {
        $data['create_time'] = time();
        $model->save($data);
        return true;
      }

      return false;
    }

    public function hasClockRecord($lesson_id, $order_id, $user_id) {
      $model = $this->where(['lesson_id' => $lesson_id, 'order_id' => $order_id,'user_id' => $user_id])->findOrEmpty();
      if($model->isEmpty()) {
        return false;
      }

      return true;
    }
}
